//
//  ZZFLocationView.m
//  YYUDemo
//
//  Created by zsp on 2017/3/17.
//  Copyright © 2017年 zsp. All rights reserved.
//

#import "ZZFLocationView.h"

#import <Masonry.h>

#import "ZZFConfigSet.h"
#import "UIColor+ZZFExtend.h"

@interface ZZFLocationView ()

@property(nonatomic, strong)UIButton *locationButton;
@property(nonatomic, strong)UISwitch *locationSwitch;
@property(nonatomic, strong)UILabel *locationSwitchStateLabel;
@property(nonatomic, strong)UILabel *locationLabel;

@property(nonatomic, assign)BOOL locationFlag;

@end

@implementation ZZFLocationView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (instancetype)init {
    if (self=[super init]) {
        [self configView];
    }
    return self;
}

- (void)updateData:(id)data atIndexPath:(NSIndexPath*)indexPath {
    if (data) {
        
    }else{
        self.locationLabel.text=@"福建省厦门市思明区观日路336号18楼502室";
        self.locationSwitchStateLabel.text=@"打开";
    }
    
}

- (void)stateChanged:(UISwitch*)stateSwitch {
    self.locationFlag=stateSwitch.on;
    self.locationSwitchStateLabel.text=self.locationFlag? @"打开":@"关闭";
}

- (void)configView {
    self.locationButton=[UIButton buttonWithType:UIButtonTypeCustom];
    [self.locationButton setImage:[UIImage imageNamed:@"location"] forState:UIControlStateNormal];
    [self.locationButton setTitle:@"我的位置" forState:UIControlStateNormal];
    [self addSubview:self.locationButton];
    
    
    self.locationLabel=[UILabel new];
    self.locationLabel.font=[UIFont systemFontOfSize:fontSize_11];
    self.locationLabel.textColor=[UIColor colorWithHexString:colorHex_subtitle_gray_1];
    [self addSubview:self.locationLabel];
    
    self.locationSwitch=[[UISwitch alloc] init];
    [self.locationSwitch addTarget:self action:@selector(stateChanged:) forControlEvents:UIControlEventValueChanged];
    [self addSubview:self.locationSwitch];
    
    self.locationSwitchStateLabel=[UILabel new];
    self.locationSwitchStateLabel.font=[UIFont systemFontOfSize:fontSize_11];
    self.locationSwitchStateLabel.textColor=[UIColor colorWithHexString:colorHex_subtitle_gray_1];
    [self addSubview:self.locationSwitchStateLabel];
    
    
    [self.locationButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(self).offset(15);
        make.top.equalTo(self).offset(10);
        make.height.mas_equalTo(30);
        make.width.mas_equalTo(120);
    }];
    
    [self.locationLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self).offset(-2);
        make.leading.equalTo(self.locationButton);
        make.trailing.equalTo(self).offset(-120);
    }];
    
    [self.locationSwitchStateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.equalTo(self).offset(-15);
        make.centerY.equalTo(self);
        make.width.mas_equalTo(30);
    }];
    
    [self.locationSwitch mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.equalTo(self.locationSwitchStateLabel.mas_leading).offset(-10);
        make.centerY.equalTo(self);
        make.width.mas_equalTo(50);
    }];
    
    [self updateData:nil atIndexPath:nil];
}

@end
